package com.generator.marketManage.orderVerify.service.impl;

import com.generator.marketManage.orderVerify.dao.OrderVerifyMap;
import com.generator.marketManage.orderVerify.pojo.Order;
import com.generator.marketManage.orderVerify.pojo.OrderCondition;
import com.generator.marketManage.orderVerify.pojo.OrderDetail;
import com.generator.marketManage.orderVerify.service.IOrderVerifyService;
import com.generator.util.PageModel;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class OrderVerifyService implements IOrderVerifyService {
    @Autowired
    private OrderVerifyMap orderVerifyMap;

    public OrderVerifyMap getOrderVerifyMap() {
        return orderVerifyMap;
    }

    public void setOrderVerifyMap(OrderVerifyMap orderVerifyMap) {
        this.orderVerifyMap = orderVerifyMap;
    }

    @Override
    //    条件查询处于审核中的订单
    public PageModel<Order> queryOrder(OrderCondition condition, PageModel<Order> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum()<=0?1:pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize()<=0?1:pageModel.getPageSize());

        Page<Object> pageinfo = PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<Order> list = orderVerifyMap.queryOrder(condition);

        PageInfo<Order> warehousePageInfo = new PageInfo<Order>(list);

        pageModel.setData(new ArrayList<Order>(list));
        pageModel.setTotalPage(warehousePageInfo.getPages());
        pageModel.setTotalRows(warehousePageInfo.getTotal());

        return pageModel;
    }

    @Override
    //订购单编号查询订单详情
    public List<Order> queryOrderById(OrderCondition orderCondition) {
        return orderVerifyMap.queryOrder(orderCondition);
    }

    //    根据订单id查询订单明细
    public List<OrderDetail> queryOrderDetailById(OrderDetail orderDetail){
        return orderVerifyMap.queryOrderDetailById(orderDetail);
    }

    //    修改订购单审核信息
    public Integer updateOpinion(Order order){
        return orderVerifyMap.updateOpinion(order);
    }
}
